﻿var VmYz = new Vue({
    data: {
        fullscreenLoading: false
    },
    methods: {
        alert: function (msg, type) {
            var aType = "info";
            if (type != undefined) {
                aType = type;
            }
            this.$alert(msg, "提示", {
                confirmButtonText: '确定',
                type: aType
            });
        },
        confirm: function (msg, func, type, errFunc) {
            var cType = "warning";
            if (type != undefined) {
                cType = type;
            }
            this.$confirm(msg, '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: cType
            }).then(() => {
                if (func != undefined) {
                    func();
                }
            }).catch(() => {
                if (errFunc != undefined) {
                    errFunc();
                }
            });
        },
        loading: function (autoClose, second) {
            this.fullscreenLoading = true;
            var time = 2;
            if (second != undefined) {
                time = time * second;
            }
            if (autoClose != undefined && autoClose) {
                setTimeout(() => {
                    this.fullscreenLoading = false;
                }, time);
            }
        },
        closeLoading: function () {
            this.fullscreenLoading = false;
        },
        message: function (msg, type) {
            if (type == undefined) { 
                this.$message({
                    message: msg,
                    type: "warning"
                });
            }
            else if (type) {
                this.$message({
                    message: msg,
                    type: "success"
                });
            }
            else {
                this.$message.error(msg);
            }
        },
        getMenuLong: function () {
            var menuLong = localStorage.getItem("menuLong");
            if (menuLong == undefined || menuLong == null) {
                menuLong = 1;
                localStorage.setItem("menuLong", menuLong);
            }
            return menuLong == "1";
        },
        setMenuLong: function (menuLong) {
            var mlong = menuLong ? "1" : "0";
            localStorage.setItem("menuLong", mlong);
        }
    }
});

///校验手机号
var checkMobile = function (rule, value, callback) {
    var mobile = /^1\d{10}$/;
    if (!mobile.test(value)) {
        callback(new Error('手机号不合法'));
    }
    else {
        callback();
    }
};